package com.ycl.bookstore.controller;

import com.ycl.bookstore.common.Result;
import com.ycl.bookstore.service.ShoppingCartService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shop")
public class ShopController {

    @Resource
    private ShoppingCartService shoppingCartService;

    /**
     * 购物车列表
     * @param title
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/shopCart")
    public Result getShopList(@RequestParam(value = "title",required = false) String title,
                              @RequestParam("pageNo") Long pageNo,
                              @RequestParam("pageSize") Long pageSize){
        return shoppingCartService.getShopList(title,pageNo,pageSize);
    }

    /**
     * 加入购物车
     * @param bookId
     * @return
     */
    @PostMapping("/add/{id}")
    public Result addShopCart(@PathVariable("id") String bookId){
        return shoppingCartService.addShopCart(bookId);
    }

    /**
     * 取消购物车
     * @param bookId
     * @return
     */
    @PutMapping("/cancel/{id}")
    public Result cancelShopCart(@PathVariable("id") Long bookId){
        return shoppingCartService.cancelShopCart(bookId);
    }

    /**
     * 清除购物车
     * @return
     */
    @DeleteMapping("/clear")
    public Result clearShopCart(){
        return shoppingCartService.clearShopCart();
    }
}
